<?php
// +----------------------------------------------------------------------
// | Citrix [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.tpCitrix.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.tpCitrix.com/ )
// +----------------------------------------------------------------------
// | Author: Citrix < 2722279500@qq.com >
// +----------------------------------------------------------------------

namespace app\index\controller;

use \think\Cache;
use \think\Controller;
use \think\Loader;
use \think\Db;
use \think\Session;
use \think\View;
class Base extends controller
{
    public function __construct()
    {
        parent::__construct();
        $this->fetch = new View();
        $this->user_id = empty(Session::get('user_id'))?0:Session::get('user_id');
        //主导航
        $nav = Db::name('nav')->where(['pid'=>0,'type'=>1])->order('sort DESC,id DESC')->select();
        if(!empty($nav))
        {
        	foreach ($nav as $k => $v) 
        	{
        		$nav[$k]['show'] = Db::name('show')->where(['nav_id'=>$nav[$k]['id']])->order('sort DESC,id DESC')->select();
        	}
        }
        $user = Db::name('users')->where('id',$this->user_id)->value('fullname');//登录的会员
        //左侧
        $left_cate_id = Db::name('contemt_cate')->order('sort DESC')->limit(0,2)->select();
        if(!empty($left_cate_id[1]['id']))
        {
            $left_contemt = Db::name('contemt')->field('title,qq')->where('contemt_cate_id',$left_cate_id[1]['id'])->order('sort DESC')->select();
            $this->assign('left_contemt',$left_contemt);
        }

        //底部导航条
        $bottom_nav = Db::name('nav')->where(['pid'=>0,'type'=>3])->order('sort DESC,id DESC')->select();

        $web_config = Db::name('webconfig')->where('web','web')->find();

		// 内容碎片 
        $fragment_list = Db::name('fragment')->select();
		foreach ($fragment_list as $key => $value) {
		    $fragment[$fragment_list[$key]['mark']] = array (
		        "name" => $fragment_list[$key]['fragment_name'],
		        "image" => $fragment_list[$key]['image'],
		        "text" => $fragment_list[$key]['text'],
		        "link" => $fragment_list[$key]['link']
		    );
		}
		$this->assign('fragment',$fragment); //内容碎片

        $this->assign('web_config',$web_config);
        $this->assign('web_title','');
        $this->assign('bottom_nav',$bottom_nav);
        $this->assign('nav',$nav);
        $this->assign('user',$user);
    }
}
